home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_posix.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  6KB  |  223 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''Test posix functions'''
  5. from test import test_support
  6.  
  7. try:
  8.     import posix
  9. except ImportError:
  10.     raise test_support.TestSkipped, 'posix is not available'
  11.  
  12. import time
  13. import os
  14. import sys
  15. import unittest
  16. import warnings
  17. warnings.filterwarnings('ignore', '.* potential security risk .*', RuntimeWarning)
  18.  
  19. class PosixTester(unittest.TestCase):
  20.     
  21.     def setUp(self):
  22.         fp = open(test_support.TESTFN, 'w+')
  23.         fp.close()
  24.  
  25.     
  26.     def tearDown(self):
  27.         os.unlink(test_support.TESTFN)
  28.  
  29.     
  30.     def testNoArgFunctions(self):
  31.         NO_ARG_FUNCTIONS = [
  32.             'ctermid',
  33.             'getcwd',
  34.             'getcwdu',
  35.             'uname',
  36.             'times',
  37.             'getloadavg',
  38.             'tmpnam',
  39.             'getegid',
  40.             'geteuid',
  41.             'getgid',
  42.             'getgroups',
  43.             'getpid',
  44.             'getpgrp',
  45.             'getppid',
  46.             'getuid']
  47.         for name in NO_ARG_FUNCTIONS:
  48.             posix_func = getattr(posix, name, None)
  49.             if posix_func is not None:
  50.                 posix_func()
  51.                 self.assertRaises(TypeError, posix_func, 1)
  52.                 continue
  53.         
  54.  
  55.     
  56.     def test_statvfs(self):
  57.         if hasattr(posix, 'statvfs'):
  58.             self.assert_(posix.statvfs(os.curdir))
  59.         
  60.  
  61.     
  62.     def test_fstatvfs(self):
  63.         if hasattr(posix, 'fstatvfs'):
  64.             fp = open(test_support.TESTFN)
  65.             
  66.             try:
  67.                 self.assert_(posix.fstatvfs(fp.fileno()))
  68.             finally:
  69.                 fp.close()
  70.  
  71.         
  72.  
  73.     
  74.     def test_ftruncate(self):
  75.         if hasattr(posix, 'ftruncate'):
  76.             fp = open(test_support.TESTFN, 'w+')
  77.             
  78.             try:
  79.                 fp.write('test')
  80.                 fp.flush()
  81.                 posix.ftruncate(fp.fileno(), 0)
  82.             finally:
  83.                 fp.close()
  84.  
  85.         
  86.  
  87.     
  88.     def test_dup(self):
  89.         if hasattr(posix, 'dup'):
  90.             fp = open(test_support.TESTFN)
  91.             
  92.             try:
  93.                 fd = posix.dup(fp.fileno())
  94.                 self.assert_(isinstance(fd, int))
  95.                 os.close(fd)
  96.             finally:
  97.                 fp.close()
  98.  
  99.         
  100.  
  101.     
  102.     def test_dup2(self):
  103.         if hasattr(posix, 'dup2'):
  104.             fp1 = open(test_support.TESTFN)
  105.             fp2 = open(test_support.TESTFN)
  106.             
  107.             try:
  108.                 posix.dup2(fp1.fileno(), fp2.fileno())
  109.             finally:
  110.                 fp1.close()
  111.                 fp2.close()
  112.  
  113.         
  114.  
  115.     
  116.     def fdopen_helper(self, *args):
  117.         fd = os.open(test_support.TESTFN, os.O_RDONLY)
  118.         fp2 = posix.fdopen(fd, *args)
  119.         fp2.close()
  120.  
  121.     
  122.     def test_fdopen(self):
  123.         if hasattr(posix, 'fdopen'):
  124.             self.fdopen_helper()
  125.             self.fdopen_helper('r')
  126.             self.fdopen_helper('r', 100)
  127.         
  128.  
  129.     
  130.     def test_fstat(self):
  131.         if hasattr(posix, 'fstat'):
  132.             fp = open(test_support.TESTFN)
  133.             
  134.             try:
  135.                 self.assert_(posix.fstat(fp.fileno()))
  136.             finally:
  137.                 fp.close()
  138.  
  139.         
  140.  
  141.     
  142.     def test_stat(self):
  143.         if hasattr(posix, 'stat'):
  144.             self.assert_(posix.stat(test_support.TESTFN))
  145.         
  146.  
  147.     
  148.     def test_chdir(self):
  149.         if hasattr(posix, 'chdir'):
  150.             posix.chdir(os.curdir)
  151.             self.assertRaises(OSError, posix.chdir, test_support.TESTFN)
  152.         
  153.  
  154.     
  155.     def test_lsdir(self):
  156.         if hasattr(posix, 'lsdir'):
  157.             self.assert_(test_support.TESTFN in posix.lsdir(os.curdir))
  158.         
  159.  
  160.     
  161.     def test_access(self):
  162.         if hasattr(posix, 'access'):
  163.             self.assert_(posix.access(test_support.TESTFN, os.R_OK))
  164.         
  165.  
  166.     
  167.     def test_umask(self):
  168.         if hasattr(posix, 'umask'):
  169.             old_mask = posix.umask(0)
  170.             self.assert_(isinstance(old_mask, int))
  171.             posix.umask(old_mask)
  172.         
  173.  
  174.     
  175.     def test_strerror(self):
  176.         if hasattr(posix, 'strerror'):
  177.             self.assert_(posix.strerror(0))
  178.         
  179.  
  180.     
  181.     def test_pipe(self):
  182.         if hasattr(posix, 'pipe'):
  183.             (reader, writer) = posix.pipe()
  184.             os.close(reader)
  185.             os.close(writer)
  186.         
  187.  
  188.     
  189.     def test_tempnam(self):
  190.         if hasattr(posix, 'tempnam'):
  191.             self.assert_(posix.tempnam())
  192.             self.assert_(posix.tempnam(os.curdir))
  193.             self.assert_(posix.tempnam(os.curdir, 'blah'))
  194.         
  195.  
  196.     
  197.     def test_tmpfile(self):
  198.         if hasattr(posix, 'tmpfile'):
  199.             fp = posix.tmpfile()
  200.             fp.close()
  201.         
  202.  
  203.     
  204.     def test_utime(self):
  205.         if hasattr(posix, 'utime'):
  206.             now = time.time()
  207.             posix.utime(test_support.TESTFN, None)
  208.             self.assertRaises(TypeError, posix.utime, test_support.TESTFN, (None, None))
  209.             self.assertRaises(TypeError, posix.utime, test_support.TESTFN, (now, None))
  210.             self.assertRaises(TypeError, posix.utime, test_support.TESTFN, (None, now))
  211.             posix.utime(test_support.TESTFN, (int(now), int(now)))
  212.             posix.utime(test_support.TESTFN, (now, now))
  213.         
  214.  
  215.  
  216.  
  217. def test_main():
  218.     test_support.run_unittest(PosixTester)
  219.  
  220. if __name__ == '__main__':
  221.     test_main()
  222.  
  223.